package grpnul.handin4;


import java.util.Comparator;
import java.util.Iterator;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Lasse
 */
public class huntington_hill_method {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        In in = new In(args[0]);
        int size =Integer.parseInt( in.readLine());
        
        
        MaxPQ<Stat> maxPQ = new MaxPQ(size,new StatCompare());
        int seats =Integer.parseInt(in.readLine())-size;
        while(in.hasNextLine())
        {
            maxPQ.insert(new Stat(in.readLine(),Integer.parseInt(in.readLine()),1));
        }
        
        while(seats > 0)
        {
            maxPQ.max().addSeats();
            maxPQ.updateMax();
            seats--;
        }
        
        Iterator<Stat> iPQ = maxPQ.iterator();
        while(iPQ.hasNext())
        {
            Stat tmp = iPQ.next();
            System.out.println("" + tmp.getName() + " " + tmp.getSeats());
        }
    }
    
    public static class StatCompare implements Comparator<Stat> {

        @Override
        public int compare(Stat o1, Stat o2) {
            return (int)(o1.getQuota()-o2.getQuota());
        }
        
    }
}
